-module(sup_server_tpl).

-behaviour(supervisor).

-export([
    start_link/01

    ,init/1
]).

-include("common.hrl").


start_link(Args) ->
    supervisor:start_link({local, ?MODULE}, ?MODULE, Args).


init(Args) ->
    CoreChildren = get_core(Args),
    ModChildren = get_mod(Args),
    NetChildren = get_net(Args),

    {ok, {{one_for_one, 2, 10}, boot_misc:make_child(CoreChildren ++ ModChildren ++ NetChildren)}}.


get_core([DirVar, FileConf]) ->
    [
        {rand_mgr, {rand_mgr, start_link, []}}
        ,{env_mgr, {env_mgr, start_link, [DirVar]}}
        ,{config_mgr, {config_mgr, start_link, [FileConf]}}
        % 时间管理器(修改应用时间、主要用于调试应用), 需要开启 debug 宏
        ,{time_mgr, {time_mgr, start_link, []}}
        ,{crontab_mgr, {crontab_mgr, start_link, []}}

        ,{db_mnesia_mgr, {db_mnesia_mgr, start_link, []}}

        % MySQL 数据库管理器, 配置在 app.conf db_mysql 下, 可以配置多个数据库, 会自动重连
        %,{db_mysql_mgr, {db_mysql_mgr, start_link, []}}
    ].

get_mod(_Args) ->
    [
        {role_mgr, {role_mgr, start_link, []}}
        ,{role_online_mgr, {role_online_mgr, start_link, []}}
        ,{role_offline_async, {role_offline_async, start_link, []}}
    ].

get_net(_Args) ->
    [
        {net_sup2, {net_sup2, start_link, []}, permanent, 10000, supervisor, [net_sup2]}
    ].
